package com.hfh.main.course.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hfh.main.course.entity.CourseListEntity;
import com.hfh.main.course.mapper.CourseListMapper;
import com.hfh.main.course.service.CourseListService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 */
@Service
public class CourseListServiceImpl extends ServiceImpl<CourseListMapper, CourseListEntity> implements CourseListService {
    @Autowired
    private CourseListMapper courseListMapper;

    @Override
    public CourseListEntity queryCourseByLeader(String param) {
        QueryWrapper<CourseListEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(("user_acc"), param);
        List<CourseListEntity> courseListEntities = courseListMapper.selectList(wrapper);
        CourseListEntity courseListEntity = courseListEntities.stream().findFirst().get();
        return courseListEntity;
    }

    @Override
    public CourseListEntity queryCourseByListId(String param) {
        QueryWrapper<CourseListEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(("list_id"), param);
        List<CourseListEntity> courseListEntities = courseListMapper.selectList(wrapper);
        CourseListEntity courseListEntity = courseListEntities.stream().findFirst().get();
        return courseListEntity;
    }

    @Override
    public void updateTeacherNull(Integer groupId) {
        courseListMapper.updateTeacherNull(groupId);
    }
}
